package com.yuanli.cosmeticmirror.persenter;

import androidx.lifecycle.LifecycleOwner;

import com.comenjoysoft.baselibrary.listener.CallbackListener;
import com.comenjoysoft.baselibrary.presenter.BasePresenter;
import com.yuanli.cosmeticmirror.model.biz.IFindPwdBiz;
import com.yuanli.cosmeticmirror.model.biz.IRegisterBiz;
import com.yuanli.cosmeticmirror.model.impl.FindPwdImpl;
import com.yuanli.cosmeticmirror.model.impl.RegisterImpl;
import com.yuanli.cosmeticmirror.model.iview.IFindPwdView;
import com.yuanli.cosmeticmirror.model.iview.IRegisterView;

public class FindPwdPersenter extends BasePresenter<IFindPwdView> {

    private final IFindPwdBiz biz;

    public FindPwdPersenter(IFindPwdView view, LifecycleOwner owner) {
        attachView(view);
        biz = new FindPwdImpl(owner);
    }

    public void getCode(String phone) {
        biz.getCodeModel(phone, new CallbackListener<String>() {
            @Override
            public void success(String object) {
                if (object.contains("一天最多")) {
                    mView.onError("获取验证码次数超出");
                    return;
                }
                mView.getCodeSuncess(object);
            }

            @Override
            public void failed(Object object) {
                mView.onError("获取验证码失败");
            }
        });
    }

    public void findPwd(String phone, String password) {
        biz.findPwd(phone, password, new CallbackListener<String>() {
            @Override
            public void success(String object) {
                if (object.contains("SUCCESS")) {
                    mView.onSucess();
                } else if (object.contains("Account does not exist")) {
                    mView.onError("账号不存在");
                } else {
                    mView.onError("找回密码失败，请重试");

                }
            }

            @Override
            public void failed(Object object) {
                mView.onError("找回密码失败，请重试");
            }
        });
    }
}
